package com.geekaca.web.servlet;

import com.alibaba.fastjson.JSON;
import com.geekaca.web.pojo.BrandType;
import com.geekaca.web.service.TypeService;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(urlPatterns = "/allTypes")
public class AllTypesServlet extends HttpServlet {
    private TypeService typeService = new TypeService();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<BrandType> typeList = typeService.selectAll();
        String s = JSON.toJSONString(typeList);

        resp.setContentType("text/json;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        writer.write(s);
        writer.flush();

    }
}
